﻿using System;
using System.Collections.Generic;
using System.Linq;
using TuxedoLib;

namespace SpaceSquirrel
{
	class PauseScene : GameSceneBase
	{
		private PlayScene bg;
		private int counter = 0;

		public PauseScene(PlayScene bg)
			: base()
		{
			this.bg = bg;
		}

		public override void ProcessInput(List<MyEvent> events, Dictionary<string, bool> pressedActions)
		{
			foreach (MyEvent ev in events)
			{
				if (ev.Down && ev.Action == "start")
				{
					if (this.bg.Flags.Contains('M'))
					{
						SoundManager.PlayNoise("pause_sound");
						JukeBox.Unpause();
					}
					this.Next = this.bg;
					this.bg.Next = this.bg;
				}
			}
		}

		public override void Update()
		{
			if (this.counter == 0 && this.bg.Flags.Contains('M'))
			{
				JukeBox.Pause();
				SoundManager.PlayNoise("pause_sound");
			}

			this.counter++;
		}

		public override void Render(Image screen, int renderCounter)
		{
			screen.Fill(0, 0, 0);
			Image img = Text.Render(-1, "PAUSE");
			int x = 128 - img.Width / 2;
			int y = 112 - img.Height / 2;
			screen.Blit(img, x, y);
		}
	}
}
